package sk.vasicek.drinkmanager.activity;

import java.util.ArrayList;
import java.util.Date;

import sk.vasicek.drinkmanager.R;
import sk.vasicek.drinkmanager.domain.Drink;
import sk.vasicek.drinkmanager.service.BackgroundAdapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class DrinkManagerActivity extends Activity {
	/** Called when the activity is first created. */
	// Beer
	private Button beerButton;
	private TextView beerCountText;
	private TextView beerCountLabel;
	private int beerCount = 0;
	private SeekBar beerBar;
	private EditText beerPrice;
	private TextView beerPriceCurrencyLabel;
	// Shot
	private Button shotButton;
	private TextView shotCountText;
	private TextView shotCountLabel;
	private int shotCount = 0;
	private SeekBar shotBar;
	private EditText shotPrice;
	private TextView shotPriceCurrencyLabel;
	// Wine
	private Button wineButton;
	private TextView wineCountText;
	private TextView wineCountLabel;
	private int wineCount = 0;
	private SeekBar wineBar;
	private EditText winePrice;
	private TextView winePriceCurrencyLabel;
	// // Soft drinks
	// // Carbonated
	// private Button carbButton;
	// private TextView carbCountText;
	// private TextView carbCountLabel;
	// private int carbCount = 0;
	// private SeekBar carbBar;
	// private EditText carbPrice;
	// private TextView carbPriceCurrencyLabel;
	// // Coffee
	// private Button coffeeButton;
	// private TextView coffeeCountText;
	// private TextView coffeeCountLabel;
	// private int coffeeCount = 0;
	// private SeekBar coffeeBar;
	// private EditText coffeePrice;
	// private TextView coffeePriceCurrencyLabel;
	// // Energy drink
	// private Button energyButton;
	// private TextView energyCountText;
	// private TextView energyCountLabel;
	// private int energyCount = 0;
	// private SeekBar energyBar;
	// private EditText energyPrice;
	// private TextView energyPriceCurrencyLabel;
	// // Mineral water
	// private Button mineralButton;
	// private TextView mineralCountText;
	// private TextView mineralCountLabel;
	// private int mineralCount = 0;
	// private SeekBar mineralBar;
	// private EditText mineralPrice;
	// private TextView mineralPriceCurrencyLabel;
	// Stats
	private Button checkStatsButton;
	private TextView finalPriceText;
	private TextView alcoholConcentrationText;
	private RatingBar drunkRating;
	protected ImageButton settingsButton;
	protected ImageButton mapButton;
	protected ImageButton placesButton;
	protected ImageButton drinksButton;

	private static String TAG = "DrinkManagerActivity";

	ArrayList<Drink> drinks = null;
	SharedPreferences prefs;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.drinkmanager);
		Log.d(TAG, "Started drink manager");
		// drinks storage
		this.drinks = new ArrayList<Drink>();
		// beer controllers
		this.beerButton = (Button) this.findViewById(R.id.beerButton);
		this.beerPrice = (EditText) this.findViewById(R.id.beerPrice);
		this.beerCountLabel = (TextView) this.findViewById(R.id.beerLabel);
		this.beerCountText = (TextView) this.findViewById(R.id.beerCount);
		this.beerPriceCurrencyLabel = (TextView) this.findViewById(R.id.beerPriceCurrency);
		this.beerBar = (SeekBar) this.findViewById(R.id.beerBar);
		// wine controllers
		this.wineButton = (Button) this.findViewById(R.id.wineButton);
		this.winePrice = (EditText) this.findViewById(R.id.winePrice);
		this.wineCountLabel = (TextView) this.findViewById(R.id.wineLabel);
		this.wineCountText = (TextView) this.findViewById(R.id.wineCount);
		this.winePriceCurrencyLabel = (TextView) this.findViewById(R.id.winePriceCurrency);
		this.wineBar = (SeekBar) this.findViewById(R.id.wineBar);
		// shot controllers
		this.shotButton = (Button) this.findViewById(R.id.shotButton);
		this.shotPrice = (EditText) this.findViewById(R.id.shotPrice);
		this.shotCountLabel = (TextView) this.findViewById(R.id.shotLabel);
		this.shotCountText = (TextView) this.findViewById(R.id.shotCount);
		this.shotPriceCurrencyLabel = (TextView) this.findViewById(R.id.shotPriceCurrency);
		this.shotBar = (SeekBar) this.findViewById(R.id.shotBar);

		// // Soft drinks
		// // Carbonated drink
		// this.carbButton = (Button)
		// this.findViewById(R.id.carbonatedDrinkButton);
		// this.carbPrice = (EditText)
		// this.findViewById(R.id.carbonatedDrinkPrice);
		// this.carbCountLabel = (TextView)
		// this.findViewById(R.id.carbonatedDrinkLabel);
		// this.carbCountText = (TextView)
		// this.findViewById(R.id.carbonatedDrinkCount);
		// this.carbPriceCurrencyLabel = (TextView)
		// this.findViewById(R.id.carbonatedDrinkPriceCurrency);
		// this.carbBar = (SeekBar) this.findViewById(R.id.carbonatedDrinkBar);
		// // Coffee
		// this.coffeeButton = (Button) this.findViewById(R.id.coffeeButton);
		// this.coffeePrice = (EditText) this.findViewById(R.id.coffeePrice);
		// this.coffeeCountLabel = (TextView)
		// this.findViewById(R.id.coffeeLabel);
		// this.coffeeCountText = (TextView)
		// this.findViewById(R.id.coffeeCount);
		// this.coffeePriceCurrencyLabel = (TextView)
		// this.findViewById(R.id.coffeePriceCurrency);
		// this.coffeeBar = (SeekBar) this.findViewById(R.id.coffeeBar);
		// // Energy drink
		// this.energyButton = (Button)
		// this.findViewById(R.id.energyDrinkButton);
		// this.energyPrice = (EditText)
		// this.findViewById(R.id.energyDrinkPrice);
		// this.energyCountLabel = (TextView)
		// this.findViewById(R.id.energyDrinkLabel);
		// this.energyCountText = (TextView)
		// this.findViewById(R.id.energyDrinkCount);
		// this.energyPriceCurrencyLabel = (TextView)
		// this.findViewById(R.id.energyDrinkPriceCurrency);
		// this.energyBar = (SeekBar) this.findViewById(R.id.energyDrinkBar);
		// // Mineral water
		// this.mineralButton = (Button)
		// this.findViewById(R.id.mineralWaterButton);
		// this.mineralPrice = (EditText)
		// this.findViewById(R.id.mineralWaterPrice);
		// this.mineralCountLabel = (TextView)
		// this.findViewById(R.id.mineralWaterLabel);
		// this.mineralCountText = (TextView)
		// this.findViewById(R.id.mineralWaterCount);
		// this.mineralPriceCurrencyLabel = (TextView)
		// this.findViewById(R.id.mineralWaterPriceCurrency);
		// this.mineralBar = (SeekBar) this.findViewById(R.id.mineralWaterBar);

		// stats controllers
		this.checkStatsButton = (Button) this.findViewById(R.id.checkStatsButton);
		this.drunkRating = (RatingBar) this.findViewById(R.id.drunkRating);
		this.finalPriceText = (TextView) this.findViewById(R.id.finalPriceText);
		this.alcoholConcentrationText = (TextView) this.findViewById(R.id.alcoholConcentration);

		String beerPriceText = "0.0";
		String winePriceText = "0.0";
		String shotPriceText = "0.0";

		prefs = PreferenceManager.getDefaultSharedPreferences(this);
		BackgroundAdapter.updateBackgroundFromPrefs(prefs, this);

		this.checkAndSetVisibility(prefs);

		boolean enableDefaultPrice = prefs.getBoolean("EnablePrice", false);
		if (enableDefaultPrice) {
			beerPriceText = prefs.getString("BeerPrice", "1.2");
			winePriceText = prefs.getString("WinePrice", "1.0");
			shotPriceText = prefs.getString("ShotPrice", "1.5");

			DrinkManagerActivity.this.shotPrice.setText(shotPriceText);
			DrinkManagerActivity.this.beerPrice.setText(beerPriceText);
			DrinkManagerActivity.this.winePrice.setText(winePriceText);
		}

		this.beerButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
				Float beerAlcoholConcentration = Float.parseFloat(prefs.getString("BeerStrength", "0.04").replaceAll(",", "."));
				Float beerVolume = Float.parseFloat(prefs.getString("BeerVolume", "0.5").replaceAll(",", "."));

				DrinkManagerActivity.this.drinks.add(new Drink(beerAlcoholConcentration, beerVolume, new Date()));

				DrinkManagerActivity.this.beerCount++;
				DrinkManagerActivity.this.beerCountText.setText(String.valueOf(DrinkManagerActivity.this.beerCount));
				DrinkManagerActivity.this.beerBar.setProgress(DrinkManagerActivity.this.beerCount);
			}
		});

		this.beerBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				DrinkManagerActivity.this.beerCount = DrinkManagerActivity.this.beerBar.getProgress();
				DrinkManagerActivity.this.beerCountText.setText(String.valueOf(DrinkManagerActivity.this.beerCount));
				// DrinkCounterActivity.this.beerBar.setProgress(DrinkCounterActivity.this.beerCount);

			}
		});
		this.shotBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				DrinkManagerActivity.this.shotCount = DrinkManagerActivity.this.shotBar.getProgress();
				DrinkManagerActivity.this.shotCountText.setText(String.valueOf(DrinkManagerActivity.this.shotCount));
				// DrinkCounterActivity.this.beerBar.setProgress(DrinkCounterActivity.this.beerCount);

			}
		});
		this.shotButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
				Float shotAlcoholConcentration = Float.parseFloat(prefs.getString("ShotStrength", "0.39").replaceAll(",", "."));
				Float shotVolume = Float.parseFloat(prefs.getString("ShotVolume", "0.05").replaceAll(",", "."));

				DrinkManagerActivity.this.drinks.add(new Drink(shotAlcoholConcentration, shotVolume, new Date()));

				DrinkManagerActivity.this.shotCount++;
				DrinkManagerActivity.this.shotCountText.setText(String.valueOf(DrinkManagerActivity.this.shotCount));
				DrinkManagerActivity.this.shotBar.setProgress(DrinkManagerActivity.this.shotCount);
			}
		});
		this.wineBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				DrinkManagerActivity.this.wineCount = DrinkManagerActivity.this.wineBar.getProgress();
				DrinkManagerActivity.this.wineCountText.setText(String.valueOf(DrinkManagerActivity.this.wineCount));
				// DrinkCounterActivity.this.beerBar.setProgress(DrinkCounterActivity.this.beerCount);

			}
		});
		this.wineButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
				Float wineAlcoholConcentration = Float.parseFloat(prefs.getString("WineStrength", "0.16").replaceAll(",", "."));
				Float wineVolume = Float.parseFloat(prefs.getString("WineVolume", "0.2").replaceAll(",", "."));

				DrinkManagerActivity.this.drinks.add(new Drink(wineAlcoholConcentration, wineVolume, new Date()));

				DrinkManagerActivity.this.wineCount++;
				DrinkManagerActivity.this.wineCountText.setText(String.valueOf(DrinkManagerActivity.this.wineCount));
				DrinkManagerActivity.this.wineBar.setProgress(DrinkManagerActivity.this.wineCount);
			}
		});
		this.checkStatsButton.setOnClickListener(new OnClickListener() {

			private float alcoholMassCoeficientBySex = new Float("0.68");
			private final float ethanolConcentration = new Float("0.8");
			private float bodyWeight = new Float("75");
			float beerAlcoholConcentration = new Float("0.04");
			float beerVolume = new Float("0.5");
			float wineAlcoholConcentration = new Float("0.16");
			float wineVolume = new Float("0.2");
			float shotAlcoholConcentration = new Float("0.39");
			float shotVolume = new Float("0.05");

			float alcoholConcentration = 0.0f;
			float drunkRating = this.alcoholConcentration * 100;

			@Override
			public void onClick(View v) {
				SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
				boolean enableBeer = false;
				enableBeer = prefs.getBoolean("EnableBeer", true);
				boolean enableWine = false;
				enableWine = prefs.getBoolean("EnableWine", true);
				boolean enableShot = false;
				enableShot = prefs.getBoolean("EnableShot", true);
				if (enableBeer) {
					this.beerAlcoholConcentration = Float.parseFloat(prefs.getString("BeerStrength", "0.04").replaceAll(",", "."));
					this.beerVolume = Float.parseFloat(prefs.getString("BeerVolume", "0.5").replaceAll(",", "."));

				}
				Log.d(TAG, "beerAlcoholConcentration = " + this.beerAlcoholConcentration);
				Log.d(TAG, "beerVolume = " + this.beerVolume);

				if (enableWine) {
					this.wineAlcoholConcentration = Float.parseFloat(prefs.getString("WineStrength", "0.16").replaceAll(",", "."));
					this.wineVolume = Float.parseFloat(prefs.getString("WineVolume", "0.2").replaceAll(",", "."));

				}
				Log.d(TAG, "wineAlcoholConcentration = " + this.wineAlcoholConcentration);
				Log.d(TAG, "wineVolume = " + this.wineVolume);

				if (enableShot) {
					this.shotAlcoholConcentration = Float.parseFloat(prefs.getString("ShotStrength", "0.39").replaceAll(",", "."));
					this.shotVolume = Float.parseFloat(prefs.getString("ShotVolume", "0.05").replaceAll(",", "."));
				}
				Log.d(TAG, "shotAlcoholConcentration = " + this.shotAlcoholConcentration);
				Log.d(TAG, "shotVolume = " + this.shotVolume);

				int gender = Integer.parseInt(prefs.getString("Gender", "1"));
				switch (gender) {
				case 1:
					this.alcoholMassCoeficientBySex = 0.70f;
					break;
				case 2:
					this.alcoholMassCoeficientBySex = 0.60f;
					break;
				default:
					Log.d(TAG, "In alcoholMassCoeficientBySex loading had to take default value");
					this.alcoholMassCoeficientBySex = 0.70f;
					break;
				}
				Log.d(TAG, "alcoholMassCoeficientBySex = " + this.alcoholMassCoeficientBySex);

				this.bodyWeight = Float.parseFloat(prefs.getString("Weight", "75").replaceAll(",", "."));
				Log.d(TAG, "bodyWeight = " + this.bodyWeight);

				this.alcoholConcentration = (((DrinkManagerActivity.this.beerCount * this.beerVolume * this.beerAlcoholConcentration * this.ethanolConcentration)
						+ (DrinkManagerActivity.this.shotCount * this.shotVolume * this.shotAlcoholConcentration * this.ethanolConcentration) + (DrinkManagerActivity.this.wineCount * this.wineVolume
						* this.wineAlcoholConcentration * this.ethanolConcentration)) / (this.bodyWeight * this.alcoholMassCoeficientBySex));
				this.drunkRating = this.alcoholConcentration * 1000f * 3f;
				Log.d(TAG, "blood alcohol concentration = " + this.alcoholConcentration);

				float beerFinalPrice = new Float("0.0");
				float shotFinalPrice = new Float("0.0");
				float wineFinalPrice = new Float("0.0");

				if (enableBeer) {
					if (DrinkManagerActivity.this.beerCount > 0 && DrinkManagerActivity.this.beerPrice != null && DrinkManagerActivity.this.beerPrice.getText().toString() != "") {
						try {
							beerFinalPrice = DrinkManagerActivity.this.beerCount * Float.parseFloat(DrinkManagerActivity.this.beerPrice.getText().toString().replaceAll(",", "."));
						} catch (NumberFormatException e) {
							Toast toast = Toast.makeText(DrinkManagerActivity.this.getApplicationContext(), getResources().getText(R.string.beerPricePrompt), Toast.LENGTH_SHORT);
							toast.show();
						}
					}
				}

				if (enableWine) {
					if (DrinkManagerActivity.this.wineCount > 0 && DrinkManagerActivity.this.winePrice != null && DrinkManagerActivity.this.winePrice.getText().toString() != "") {
						try {
							wineFinalPrice = DrinkManagerActivity.this.wineCount * Float.parseFloat(DrinkManagerActivity.this.winePrice.getText().toString().replaceAll(",", "."));
						} catch (NumberFormatException e) {
							Toast toast = Toast.makeText(DrinkManagerActivity.this.getApplicationContext(), getResources().getText(R.string.winePricePrompt), Toast.LENGTH_SHORT);
							toast.show();
						}
					}
				}

				if (enableShot) {
					if (DrinkManagerActivity.this.shotCount > 0 && DrinkManagerActivity.this.shotPrice != null && DrinkManagerActivity.this.shotPrice.getText().toString() != "") {
						try {
							shotFinalPrice = DrinkManagerActivity.this.shotCount * Float.parseFloat(DrinkManagerActivity.this.shotPrice.getText().toString().replaceAll(",", "."));
						} catch (NumberFormatException e) {
							Toast toast = Toast.makeText(DrinkManagerActivity.this.getApplicationContext(), getResources().getText(R.string.shotPricePrompt), Toast.LENGTH_SHORT);
							toast.show();
						}
					}
				}

				float finalPrice = beerFinalPrice + shotFinalPrice + wineFinalPrice;
				DrinkManagerActivity.this.finalPriceText.setText(String.valueOf(finalPrice) + "");
				Log.d(TAG, "price = " + String.valueOf(finalPrice) + "");
				DrinkManagerActivity.this.alcoholConcentrationText.setText(String.valueOf(this.alcoholConcentration * 1000) + " \u2030");
				Log.d(TAG, "alcoholConcentration = " + String.valueOf(this.alcoholConcentration * 1000) + " \u2030");

				DrinkManagerActivity.this.drunkRating.setRating(this.drunkRating);
				// Toast.makeText(DrinkManagerActivity.this.getApplicationContext(),
				// "Alcohol concentration is: " +
				// String.valueOf(this.alcoholConcentration * 1000) + " ‰",
				// Toast.LENGTH_SHORT).show();
			}
		});
		
		this.mapButton = (ImageButton) this.findViewById(R.id.map);
		this.mapButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// Toast.makeText(getApplicationContext(),
				// getResources().getText(R.string.alreadyToast),
				// Toast.LENGTH_SHORT).show();

				Intent intent = new Intent(getApplicationContext(), DrinkMapsActivity.class);
				startActivity(intent);
			}
		});
		this.placesButton = (ImageButton) this.findViewById(R.id.places);
		this.placesButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), DrinkPlacesActivity.class);
				startActivity(intent);
			}
		});

		this.settingsButton = (ImageButton) this.findViewById(R.id.settings);
		this.settingsButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
				startActivity(intent);
			}
		});

		this.drinksButton = (ImageButton) this.findViewById(R.id.drinks);
		this.drinksButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// Intent intent = new Intent(getApplicationContext(),
				// DrinkManagerActivity.class);
				// startActivity(intent);
				Toast.makeText(getApplicationContext(), getResources().getText(R.string.alreadyToast), Toast.LENGTH_SHORT).show();

			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = this.getMenuInflater();
		inflater.inflate(R.menu.optionmenu, menu);
		MenuItem settings = menu.findItem(R.id.settings);
		settings.setIntent(new Intent(this, SettingsActivity.class));
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.exit:
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage(getResources().getText(R.string.exitPrompt)).setCancelable(true).setPositiveButton(getResources().getText(R.string.yesAnswer), new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					Toast.makeText(DrinkManagerActivity.this.getApplicationContext(), getResources().getText(R.string.exitMessage), Toast.LENGTH_SHORT).show();
					DrinkManagerActivity.this.finish();
				}
			}).setNegativeButton(getResources().getText(R.string.noAnswer), new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.cancel();
				}
			});
			AlertDialog alert = builder.create();
			alert.show();
			// this.onDestroy();
			return true;
		case R.id.settings:
			Intent settingsIntent = item.getIntent();
			DrinkManagerActivity.this.startActivityForResult(settingsIntent, 0);
			return true;
		case android.R.id.home:
			Toast.makeText(DrinkManagerActivity.this.getApplicationContext(), getResources().getText(R.string.alreadyToast), Toast.LENGTH_SHORT).show();
			// Intent intent = new Intent(this, DrinkManagerActivity.class);
			// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			// startActivity(intent);
            return true;
		case R.id.drinks:
			Toast.makeText(DrinkManagerActivity.this.getApplicationContext(), getResources().getText(R.string.alreadyToast), Toast.LENGTH_SHORT).show();
			return true;
		case R.id.places:
			Intent placesIntent = new Intent(getApplicationContext(), DrinkPlacesActivity.class);
			this.startActivityForResult(placesIntent, 0);
			return true;
//		case R.id.graphs:
//			Intent graphsIntent = new Intent(getApplicationContext(), DrinkGraphActivity.class);
//			this.startActivityForResult(graphsIntent, 0);
//			return true;
		case R.id.back:
			Intent backIntent = new Intent(getApplicationContext(), BackgroundChooserActivity.class);
			this.startActivityForResult(backIntent, 0);
			return true;
		case R.id.map:
			Intent mapsIntent = new Intent(getApplicationContext(), DrinkMapsActivity.class);
			DrinkManagerActivity.this.startActivityForResult(mapsIntent, 0);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		Log.d(TAG, "Resumed to drink manager screen");
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
		BackgroundAdapter.updateBackgroundFromPrefs(prefs, this);
		this.drinks = new ArrayList<Drink>();
		this.checkAndSetVisibility(prefs);
	}

	public void checkAndSetVisibility(SharedPreferences prefs) {
		boolean enableDrinks = prefs.getBoolean("EnableDrinks", false);
		boolean enableSoftDrinks = prefs.getBoolean("EnableSoftDrinks", false);
		boolean enableBeer = false;
		enableBeer = prefs.getBoolean("EnableBeer", true);
		boolean enableWine = false;
		enableWine = prefs.getBoolean("EnableWine", true);
		boolean enableShot = false;
		enableShot = prefs.getBoolean("EnableShot", true);

		if (!enableBeer) {
			this.beerButton.setVisibility(android.view.View.INVISIBLE);
			this.beerPrice.setVisibility(android.view.View.INVISIBLE);
			this.beerCountLabel.setVisibility(android.view.View.INVISIBLE);
			this.beerCountText.setVisibility(android.view.View.INVISIBLE);
			this.beerBar.setVisibility(android.view.View.INVISIBLE);
			this.beerPriceCurrencyLabel.setVisibility(android.view.View.INVISIBLE);
			this.beerCount = 0;
			this.beerBar.setProgress(0);
		} else {
			this.beerButton.setVisibility(android.view.View.VISIBLE);
			this.beerPrice.setVisibility(android.view.View.VISIBLE);
			this.beerCountLabel.setVisibility(android.view.View.VISIBLE);
			this.beerCountText.setVisibility(android.view.View.VISIBLE);
			this.beerBar.setVisibility(android.view.View.VISIBLE);
			this.beerPriceCurrencyLabel.setVisibility(android.view.View.VISIBLE);
		}
		if (!enableWine) {
			this.wineButton.setVisibility(android.view.View.INVISIBLE);
			this.winePrice.setVisibility(android.view.View.INVISIBLE);
			this.wineCountLabel.setVisibility(android.view.View.INVISIBLE);
			this.wineCountText.setVisibility(android.view.View.INVISIBLE);
			this.wineBar.setVisibility(android.view.View.INVISIBLE);
			this.winePriceCurrencyLabel.setVisibility(android.view.View.INVISIBLE);
			this.wineCount = 0;
			this.wineBar.setProgress(0);
		} else {
			this.wineButton.setVisibility(android.view.View.VISIBLE);
			this.winePrice.setVisibility(android.view.View.VISIBLE);
			this.wineCountLabel.setVisibility(android.view.View.VISIBLE);
			this.wineCountText.setVisibility(android.view.View.VISIBLE);
			this.wineBar.setVisibility(android.view.View.VISIBLE);
			this.winePriceCurrencyLabel.setVisibility(android.view.View.VISIBLE);
		}
		if (!enableShot) {
			this.shotButton.setVisibility(android.view.View.INVISIBLE);
			this.shotPrice.setVisibility(android.view.View.INVISIBLE);
			this.shotCountLabel.setVisibility(android.view.View.INVISIBLE);
			this.shotCountText.setVisibility(android.view.View.INVISIBLE);
			this.shotBar.setVisibility(android.view.View.INVISIBLE);
			this.shotPriceCurrencyLabel.setVisibility(android.view.View.INVISIBLE);
			this.shotCount = 0;
			this.shotBar.setProgress(0);
		} else {
			this.shotButton.setVisibility(android.view.View.VISIBLE);
			this.shotPrice.setVisibility(android.view.View.VISIBLE);
			this.shotCountLabel.setVisibility(android.view.View.VISIBLE);
			this.shotCountText.setVisibility(android.view.View.VISIBLE);
			this.shotBar.setVisibility(android.view.View.VISIBLE);
			this.shotPriceCurrencyLabel.setVisibility(android.view.View.VISIBLE);
		}

		if (enableDrinks) {

		} else {

		}
		if (enableSoftDrinks) {

		} else {

		}

		
	}

	@Override
	protected void onPause() {
		super.onPause();
		Log.d(TAG, "Paused drink manager screen");
	}

	@Override
	protected void onDestroy() {
		Log.d(TAG, "Destroyed drink manager screen");
		this.drinks = new ArrayList<Drink>();
		super.onDestroy();
	}
}